package cn.whuc.scala.functional

object Concept {
  def main(args: Array[String]): Unit = {
    // 求1-5的平方和
    // 传统的命令式编程
    var sum1:Int = 0
    for(i<- 1 to 5){
      sum1+=i*i
    }
    println(sum1)

    // 函数式编程
    val list : List[Int] = List(1,2,3,4,5)
    val reult: Int = list.map((num) => {
      num * num
    }).reduce((x: Int, y: Int) => {
      x + y
    })

    println("函数式编程："+reult)
  }

}
